﻿using BusinessLogicLayer;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PresentationLayer
{
    public partial class FormTimKiemDA : Form
    {
        public FormTimKiemDA()
        {
            InitializeComponent();
        }

        private void FormTimKiemDA_Load(object sender, EventArgs e)
        {
            for (int i = 1; i <= 12; i++)
            {
                cbbThang.Items.Add(i.ToString());
            }
            for (int i = 2010; i <= 2020; i++)
            {
                cbbNam.Items.Add(i.ToString());
            }
            ActionResultAsList<DuAn> dsda = new DuAnManager().LayDSDA();  
            foreach (var item in dsda.ObjectList)
            {
                cbbTenDA.AutoCompleteCustomSource.Add(item.TenDuAn);
            }
            cbbTenDA.AutoCompleteSource = AutoCompleteSource.CustomSource;
            cbbTenDA.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            cbbTenDA.DataSource = dsda.ObjectList;
            cbbTenDA.DisplayMember = "TenDuAn";
            cbbTenDA.ValueMember = "MaDuAn";
            if (radThangNam.Checked == true)
            {
                cbbTenDA.Visible = false;
                lblTenDA.Visible = false;
            }
            else
            {
                cbbNam.Visible = false;
                cbbThang.Visible = false;
                lblNam.Visible = false;
                lblThang.Visible = false;
            }
        }
        public TimDSDA TimDS { get; set; }
        public int i { get; set; }
        public int thang { get; set; }
        public int nam { get; set; }
        public string tenDA { get; set; }
        private void btnTim_Click(object sender, EventArgs e)
        {

            thang = int.Parse(cbbThang.Text);
            nam = int.Parse(cbbNam.Text);
            tenDA = cbbTenDA.Text;
            if (radThangNam.Checked == true)
            {
                TimDS(i = 1, thang, nam, tenDA);
            }
            else
            {
                if (cbbTenDA.Text == "")
                    MessageBox.Show("Chưa nhập tên tìm kiếm!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                else
                    TimDS(i = 2, thang, nam, tenDA);
            }
        }

        private void radThangNam_CheckedChanged(object sender, EventArgs e)
        {
            if (radThangNam.Checked)
            {
                cbbTenDA.Visible = false;
                lblTenDA.Visible = false;
                cbbNam.Visible = true;
                cbbThang.Visible = true;
                lblNam.Visible = true;
                lblThang.Visible = true;
            }
            else
            {
                cbbNam.Visible = false;
                cbbThang.Visible = false;
                lblNam.Visible = false;
                lblThang.Visible = false;
                cbbTenDA.Visible = true;
                lblTenDA.Visible = true;
            }
        }
    }
}
